{extend name="base"/}
{block name="content"}
<div id="header-frame">
    {include file="public:top" /}
    <script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery-2.0.3.min.js'></script>
    <script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery.form.js'></script>
    <link href="__STATIC__/admin/uploadajax/css/style.css" type="text/css" rel="stylesheet"/>
    <link href="__STATIC__/admin/css/product_types_index.css" type="text/css" rel="stylesheet"/>
</div>
<div id="frame-body">
    <div id="menu-frame" style="width: 100%;float: left;">
        {include file="public:menu" /}


    </div>
    <div id="main-frame" style="float: left;">
        <div id="dcMain" style="margin-left: 0px;width: 1682px;">
            <div id="urHere">DouPHP 管理中心<b>></b><strong>商品分类</strong> </div>   <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3><a href="{:url('admin/product_types/add')}" class="actionBtn add">添加分类</a>商品分类</h3>

            <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic" _level="1">
                <tr bgcolor="#FBFBFB" level="1">
                    <th  align="left">分类名称</th>
                    <th  align="left">编号</th>
                    <th align="left">简单描述</th>
                    <th  align="center">排序</th>
                    <th  align="center">操作</th>
                </tr>
                {foreach name="arr" item="vo"}
                <tr bgcolor="#FFFFFF" class="1" id="{$vo['protype_id']}">
                    <td  align="left"><img src="__STATIC__/admin/images/menu_plus.gif" _id="0" onclick="rowClicked({$vo['protype_id']}) "/>{$vo['protype_name']}</td>
                    <td  align="left">{$vo['protype_number']}</td>
                    <td align="left">{$vo['protype_describe']}</td>
                    <td  align="center">{$vo['protype_sort']}</td>
                    <td  align="center" class="buttonOn"><a href="{:url('admin/ProductTypes/edit')}?id={$vo['protype_id']}">修改</a> | <a  onclick="shelf({$vo['protype_id']})">下架</a></td>
                </tr>
                {/foreach}
            </table>
        </div>
        </div>
        <div class="clear"></div>
        <script type="text/javascript">
            //删除分类
            function protypes_dele(message, id) {
                layer.open({
                    content : message,
                    icon:3,
                    btn : ['是','否'],
                    yes : function(){
                        var url="{:url('admin/protype/protype_dele')}";
                        var success_url="{:url('admin/protypes_index/index')}";
                        $.post(url,{'protype_id':id},function(result){
                            if(result.status=='4')
                            {
                                dialog.success(result.message,success_url);
                            }else
                            {
                                dialog.error(result.message);
                            }
                        })
                    }
                });
            }
            function rowClicked(id){
//          	var arr=[parseInt($(that).parents("tr").attr("class"))+1];           	
//              var trArr=$(that).parents("tr").siblings()
//	        		for(var i=1;i<trArr.length;i++){
//	        			arr.push(parseInt(trArr.eq(i).attr("class")))	        			
//	        		} 	
//              var maxNum=Math.max.apply(null, arr);
               var MaxNum=parseInt($(".tableBasic").attr("_level"));
               var  _id=$("#"+id).children('td').eq(0).children('img').attr("_id");
                var level = parseInt($("#" + id).attr("class")) + 1;
               if(_id==0) {
                   $("#" + id).children('td').eq(0).children('img').attr("_id", "1");

                   $("#" + id).children('td').eq(0).children('img').attr("src", "__STATIC__/admin/images/menu_minus.gif");
                   $("#" + id).siblings().remove("."+level);
                   for(var j=1;j<=MaxNum;j++){
                       if(level==j){
                           var trArr=$("#" + id).siblings();
                           for(var i=0;i<trArr.length;i++){
                               if(parseInt(trArr.eq(i).attr("class"))==level-1){
                                   trArr.eq(i).find("img").attr("src","__STATIC__/admin/images/menu_plus.gif")
                                   trArr.eq(i).find("img").attr("_id","0")
                               }
                           }
                       }
                   }
                   $.ajax({
                       url: "{:url('admin/product_types/getPareArr')}",
                       type: "post",
                       dataType: "json",
                       data: "id=" + id,
                       success: function (res) {
                           var id = res.id;
                           var data = res.data;
                           //alert(level);
                           console.log(data);
                           if (data == "") {
                           } else {
                               $(data).each(function (k, v) {
                                   str = '<tr bgcolor="#FFFFFF" class="' + level + ' tr' + level + '"  id="' + v['protype_id'] + '"><td  align="left"><img src="__STATIC__/admin/images/menu_plus.gif" _id="0" onclick="rowClicked(' + v['protype_id'] + ')"/>' + v['protype_name'] + '</td>'
                                       + '<td  align="left">' + v['protype_number'] + '</td>'
                                       + '<td align="left">' + v['protype_describe'] + '</td>'
                                       + '<td  align="center">' + v['protype_sort'] + '</td>'
                                       + '<td  align="center" class="buttonOn"><a href="{:url('admin/ProductTypes/edit')}?id='+v['protype_id']+'">修改</a>  | <a  onclick="shelf('+v['protype_id']+')">下架</a></td>'
                                       + '</tr>';
                                   $("#" + id).after(str);
                                   $(".tableBasic").attr("_level",level);
                               });
                           }
                       }
                   });
               }else
               {
                   $("#" + id).children('td').eq(0).children('img').attr("_id", "0");
                   $("#" + id).children('td').eq(0).children('img').attr("src", "__STATIC__/admin/images/menu_plus.gif");
                   for(var j=1;j<=MaxNum;j++){
                       if(level==j){
                           var trArr=$("#" + id).siblings();
                           for(var i=0;i<trArr.length;i++){
                                   if(parseInt(trArr.eq(i).attr("class"))>level-1){
                                       trArr.eq(i).detach()
                                   }
                           }
                       }
                   }
               }
            }
            function shelf(id){
                var url="{:url('admin/product_types/shelf')}";
                var success_url="{:url('admin/product/product_types')}";
                var data={id:id};
                $.post(url,data,function(result){
                    if(result.status=='4')
                    {
                        dialog.success(result.message,success_url);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })

            }
        </script>
        {/block}